/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.model.femModel.problemDriver;

import br.ufmg.dees.insane.model.femModel.element.Element;
import br.ufmg.dees.insane.model.femModel.element.ThinPlateElement;
import br.ufmg.dees.insane.util.IMatrix;
import br.ufmg.dees.insane.util.IVector;

/**
 * Class representing ClassicLinearProblemDriver
 * @author Samir
 * @since 12/09/2006
 */
public abstract class KirchhoffThinPlate implements ProblemDriver {

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.model.femModel.problemDriver.ProblemDriver#getA(br.ufmg.dees.insane.model.femModel.element.Element)
     */
    public IMatrix getA(Element e) {
        return null;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.model.femModel.problemDriver.ProblemDriver#getB(br.ufmg.dees.insane.model.femModel.element.Element)
     */
    public IMatrix getB(Element e) {
        return null;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.model.femModel.problemDriver.ProblemDriver#getC(br.ufmg.dees.insane.model.femModel.element.Element)
     */
    public abstract IMatrix getC(Element e);       

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.model.femModel.problemDriver.ProblemDriver#getR(br.ufmg.dees.insane.model.femModel.element.Element)
     */
	public IVector getE(Element e) {
	    IVector E = new IVector(((ThinPlateElement)e).getNumberOfDegreesOfFreedom());
	    return E;
	    
	}

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.model.femModel.problemDriver.ProblemDriver#getF(br.ufmg.dees.insane.model.femModel.element.Element)
     */
    public IVector getF(Element e){
    	return null;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.model.femModel.problemDriver.ProblemDriver#getIncrementalA(br.ufmg.dees.insane.model.femModel.element.Element)
     */
    public IMatrix getIncrementalA(Element e) {
        return null;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.model.femModel.problemDriver.ProblemDriver#getIncrementalB(br.ufmg.dees.insane.model.femModel.element.Element)
     */
    public IMatrix getIncrementalB(Element e) {
        return null;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.model.femModel.problemDriver.ProblemDriver#getIncrementalC(br.ufmg.dees.insane.model.femModel.element.Element)
     */
    public IMatrix getIncrementalC(Element e){
    	return getC(e);
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.model.femModel.problemDriver.ProblemDriver#getTotalA(br.ufmg.dees.insane.model.femModel.element.Element)
     */
    public IMatrix getTotalA(Element e) {
        return null;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.model.femModel.problemDriver.ProblemDriver#getTotalB(br.ufmg.dees.insane.model.femModel.element.Element)
     */
    public IMatrix getTotalB(Element e) {
        return null;
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.model.femModel.problemDriver.ProblemDriver#getTotalC(br.ufmg.dees.insane.model.femModel.element.Element)
     */
    public IMatrix getTotalC(Element e){
    	return getC(e);
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.model.femModel.problemDriver.ProblemDriver#getStateVariable()
     */
    public String getStateVariableLabel() {
      return "Displacements";
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.model.femModel.problemDriver.ProblemDriver#getDualVariable()
     */
    public String getDualVariableLabel() {
      return "Loads";
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.model.femModel.problemDriver.ProblemDriver#getInternalVariable()
     */
    public String getInternalVariableLabel() {
      return "Epsilon";
    }

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.model.femModel.problemDriver.ProblemDriver#getInternalDualVariable()
     */
    public String getInternalDualVariableLabel() {
      return "Sigma";
    }
	
    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.model.femModel.problemDriver.ProblemDriver#getMPInternalVariableLabel()
     */
	public String getMPInternalVariableLabel() {
		return "Strains";
	}

    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.model.femModel.problemDriver.ProblemDriver#getMPInternalDualVariableLabel()
     */
	public String getMPInternalDualVariableLabel() {
		return "Stress";
	}
    
	/** Returns the centroid of the element.
	 *  @param cN The matrix containing nodal coordinates in cartesian system.
	 *  @return the centroid of the element.
	 */
	public IVector getCentroid(IMatrix cN){
		IVector C = new IVector(2);
		double n = cN.getNumRow();

		double x = (cN.getElement(0,0)+cN.getElement(1,0))/2;
		double y = (cN.getElement(0,1)+cN.getElement(1,1))/2;

		double xAF = 0.0;   double yAF = 0.0;   double AF = 0.0;
		
		for(int i = 0; i < (n-1); i++){
			double A = 0.0;
			double xo = 0.0;   double yo = 0.0;
			double x1 = 0.0;   double y1 = 0.0;
			double x2 = 0.0;   double y2 = 0.0;
			
			x1 = cN.getElement((i+1),0);
			y1 = cN.getElement((i+1),1);
			if(i==(n-2)){
				x2 = cN.getElement(0,0);
				y2 = cN.getElement(0,1);
			} else {
				x2 = cN.getElement((i+2),0);
				y2 = cN.getElement((i+2),1);
			}
			
			A = 0.5*(x*y1+y*x2+y2*x1-y1*x2-y*x1-x*y2);
			xo = (x+x1+x2)/3;
			yo = (y+y1+y2)/3;
			
			xAF = xAF + (xo*A);
			yAF = yAF + (yo*A);
			AF = AF + A;
		}
		
		C.setElement(0,(xAF/AF));
		C.setElement(1,(yAF/AF));
		
		return C;
	}
}
